package com.ruoyi.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.MedicineMapper;
import com.ruoyi.system.domain.Medicine;
import com.ruoyi.system.service.IMedicineService;
import com.ruoyi.common.core.text.Convert;

/**
 * 药品信息Service业务层处理
 *
 * @author 王帅
 * @date 2024-08-24
 */
@Service
public class MedicineServiceImpl extends ServiceImpl<MedicineMapper, Medicine> implements IMedicineService {
    @Autowired
    private MedicineMapper medicineMapper;

    /**
     * 查询药品信息
     *
     * @param id 药品信息主键
     * @return 药品信息
     */
    @Override
    public Medicine selectMedicineById(Long id) {
        return medicineMapper.selectMedicineById(id);
    }

    /**
     * 查询药品信息列表
     *
     * @param medicine 药品信息
     * @return 药品信息
     */
    @Override
    public List<Medicine> selectMedicineList(Medicine medicine) {
        return medicineMapper.selectMedicineList(medicine);
    }

    /**
     * 新增药品信息
     *
     * @param medicine 药品信息
     * @return 结果
     */
    @Override
    public int insertMedicine(Medicine medicine) {
        medicine.setCreateTime(DateUtils.getNowDate());
        medicine.setUpdateTime(DateUtils.getNowDate());
        SysUser sysUser = ShiroUtils.getSysUser();
        String loginName = sysUser.getUserName();
        medicine.setCreateBy(loginName);
        medicine.setUpdateBy(loginName);
        return medicineMapper.insertMedicine(medicine);
    }

    /**
     * 修改药品信息
     *
     * @param medicine 药品信息
     * @return 结果
     */
    @Override
    public int updateMedicine(Medicine medicine) {
        medicine.setUpdateTime(DateUtils.getNowDate());
        SysUser sysUser = ShiroUtils.getSysUser();
        String loginName = sysUser.getUserName();
        medicine.setUpdateBy(loginName);
        return medicineMapper.updateMedicine(medicine);
    }

    /**
     * 批量删除药品信息
     *
     * @param ids 需要删除的药品信息主键
     * @return 结果
     */
    @Override
    public int deleteMedicineByIds(String ids) {
        return medicineMapper.deleteMedicineByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除药品信息信息
     *
     * @param id 药品信息主键
     * @return 结果
     */
    @Override
    public int deleteMedicineById(Long id) {
        return medicineMapper.deleteMedicineById(id);
    }
}
